home *** CD-ROM | disk | FTP | other *** search
- Unit WaveMain;
-
- Interface
-
- Uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, mmsystem, ACMWaveIO, ExtCtrls, Buttons;
-
- Type
- TForm1 = Class(TForm)
- WaveIN1: TACMWaveIN;
- WaveOut1: TACMWaveOut;
- Panel1: TPanel;
- PaintBox1: TPaintBox;
- Panel2: TPanel;
- StartBtn: TButton;
- StopBtn: TButton;
- CloseBtn: TButton;
- SpeedButton1: TSpeedButton;
- Procedure StartBtnClick(Sender: TObject);
- Procedure StopBtnClick(Sender: TObject);
- Procedure WaveIn1Data(Sender: TObject; Data: PChar; Size: Integer);
- Procedure CloseBtnClick(Sender: TObject);
- Procedure WaveFormatClick(Sender: TObject);
- Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
- Procedure WaveIN1Open(Sender: TObject);
- Procedure WaveIN1Close(Sender: TObject);
- PRIVATE
- { Private declarations }
- PUBLIC
- { Public declarations }
- Tick: Integer;
- End;
-
- Const
- FormCaption: String = 'ACM Codec Wave Sample';
-
- Var
- Form1: TForm1;
-
- Implementation
-
- {$R *.DFM}
-
- Procedure TForm1.StartBtnClick(Sender: TObject);
- Begin
- Tick := -1;
-
- WaveOut1.WaveFormat.Assign(WaveIn1.WaveFormat);
-
- WaveIN1.OPEN;
- WaveOut1.OPEN;
-
- StartBtn.Enabled := False;
- StopBtn.Enabled := True;
- End;
-
- Procedure TForm1.StopBtnClick(Sender: TObject);
- Begin
- WaveIN1.CLOSE;
- WaveOut1.CLOSE;
-
- StartBtn.Enabled := True;
- StopBtn.Enabled := False;
- End;
-
- Procedure TForm1.WaveIn1Data(Sender: TObject; Data: PChar; Size: Integer);
- Var
- DC: HDC;
- R: TRect;
- P, S: Single;
- I: Integer;
- V: SmallInt;
- Begin
- PaintBox1.Canvas.Font.COLOR := clWhite;
- PaintBox1.Canvas.Font.Size := 14;
-
- If WaveIN1.WaveFormat.WaveFormat^.wFormatTag = WAVE_FORMAT_PCM Then
- Begin
- PaintBox1.Canvas.Pen.COLOR := clYellow;
- PaintBox1.Canvas.BRUSH.Style := bsSolid;
- PaintBox1.Canvas.BRUSH.COLOR := clBlack;
-
- PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
- DC := PaintBox1.Canvas.Handle;
-
- P := 0.0;
-
- Case WaveIN1.WaveFormat.WaveFormat^.wBitsPerSample Of
- 8:
- Begin
- S := Size / PaintBox1.Width;
- MoveToEx(DC, 0, Byte(Data^) * PaintBox1.Height Div 255, Nil);
- For I := 0 To PaintBox1.Width - 1 Do
- Begin
- LineTo(DC, I, PByte(Longint(Data) + Trunc(P))^ * PaintBox1.Height Div 255);
- P := P + S;
- End;
- End;
- 16:
- Begin
- S := (Size Div 2) / PaintBox1.Width;
- V := PSmallInt(Longint(Data))^;
- MoveToEx(DC, 0, (PaintBox1.Height Div 2) - Trunc(V * PaintBox1.Height / 65535), Nil);
- For I := 0 To PaintBox1.Width - 1 Do
- Begin
- V := PSmallInt(Longint(Data) + Trunc(P) + Trunc(P) Mod 2)^;
- LineTo(DC, I, (PaintBox1.Height Div 2) - Trunc(V * PaintBox1.Height / 65535));
- P := P + S * 2;
- End;
- End;
- End;
- End Else
- Begin
- PaintBox1.Canvas.Brush.Color := clGray;
- PaintBox1.Canvas.FillRect(PaintBox1.ClientRect);
- End;
-
-
- SetBkMode(PaintBox1.Canvas.Handle, TRANSPARENT);
- R := PaintBox1.ClientRect;
- If Tick >= 0 Then
- DrawText(PaintBox1.Canvas.Handle, PChar(Format('%5.2f BPS', [1000 * Size / (GetTickCount - Tick + 1)])), -1,
- R, DT_CENTER Or DT_VCENTER);
- Tick := GetTickCount;
-
- WaveOut1.PlayBack(Data, Size);
- End;
-
- Procedure TForm1.CloseBtnClick(Sender: TObject);
- Begin
- CLOSE;
- End;
-
- Procedure TForm1.WaveFormatClick(Sender: TObject);
- Begin
- If (WaveIn1.Active) Or (WaveOut1.Active) Then
- Begin
- ShowMessage('Cannot change wave format when active !');
- Exit;
- End;
-
- WaveIN1.WaveFormat.Execute;
- WaveOut1.WaveFormat.Assign(WaveIn1.WaveFormat);
- End;
-
- Procedure TForm1.FormClose(Sender: TObject; Var Action: TCloseAction);
- Begin
- WaveIN1.CLOSE;
- WaveOut1.CLOSE;
- End;
-
- Procedure TForm1.WaveIN1Open(Sender: TObject);
- Begin
- Caption := FormCaption + ' - [Active]';
- End;
-
- Procedure TForm1.WaveIN1Close(Sender: TObject);
- Begin
- Caption := FormCaption + ' - [Inactive]';
- End;
-
-
-
- End.
-
-